<?php

namespace app\admin\controller\jy;

use app\common\controller\Backend;

/**
 * 用户访问日志管理
 * @icon fa fa-circle-o
 */
class UserAccessLog extends Backend
{
    /**
     * UserAccessLog模型对象
     * @var \app\admin\model\jy\UserAccessLog
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\jy\UserAccessLog;
    }

    public function import()
    {
        parent::import();
    }

    /**
     * 查看
     */
    public function index()
    {
        //当前是否为关联查询
        $this->relationSearch = false;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model->alias('ua')
                ->field('ua.id,ua.update_time,u.nickname,u.avatar,ui.user_id, u1.id as invite_user_id, u1.nickname as invite_nickname,u1.avatar as invite_avatar,ui.invite_type')
                ->join('jy_user_invite ui', 'ua.user_id=ui.user_id', 'LEFT')
                ->join('jy_user u', 'ua.user_id=u.id', 'LEFT')
                ->join('jy_user u1', 'ui.invite_user_id=u1.id', 'LEFT')
                ->where($where)
                ->order($sort, $order)
                ->paginate($limit);

            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }

}
